// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.

$(document).ready(function () {
    window.username = 'others';
    var wsServer = 'ws://192.168.3.138:9504';
    var websocket = new WebSocket(wsServer);

    websocket.onopen = function (evt) {
        console.log('链接成功');
        //alert('333');
    };


    websocket.onmessage = function (evt) {
        console.log(evt.data);

        var data = JSON.parse(evt.data);
        var le = data.length;
        var html = '';
        for (var i = 0; i < le; i++) {
            console.log(data[i]);
            html += '<p><a  id="aaa" onclick="aaa('+data[i].id+')" >' + data[i].name + '</a></p>'
        }
        $("#divlis").append(html);

    };

    const ipc = require('electron').ipcRenderer;
    $("#aaa").click(function () {
        alert('111'); //注册的指令。send到主进程index.js中。
    });

    function aaa()
    {
        alert('111');
    }

    $("#basic-addon2").click(function () {
        var msg = $("#in").val();
        websocket.send(msg);
        $("#in").val('');
    });
});

        // function openWindow(llsid)
        // {
        //         window.username = 'others';
        //         var wsServer = 'ws://192.168.3.138:9502';
        //         var websocket = new WebSocket(wsServer);

        //         websocket.onopen = function (evt) {
        //             console.log('链接成功');
        //             websocket.send(llsid);
        //         };

        //         websocket.onmessage = function (evt) {
        //             console.log(evt.data);
        //             var data = JSON.parse(evt.data);
        //             console.log(data);
        //         };
        // }